package com.meego.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

//******************************************************************************
//**  Date Utils - By Peter Borissow
//******************************************************************************
/**
 * Used to parse, format, and compute dates
 * ****************************************************************************
 */
public class DateUtils {

//    private Locale currentLocale = Locale.forLanguageTag("vi-VN");
    private java.util.TimeZone timeZone;
    private java.util.Date currDate;
    public static final String INTERVAL_MILLISECONDS = "S";
    public static final String INTERVAL_SECONDS = "s";
    public static final String INTERVAL_MINUTES = "m";
    public static final String INTERVAL_HOURS = "h";
    public static final String INTERVAL_DAYS = "d";
    public static final String INTERVAL_WEEKS = "w";
    public static final String INTERVAL_MONTHS = "m";
    public static final String INTERVAL_YEARS = "y";
    private static String[] SupportedFormats = new String[]{
        "EEE, d MMM yyyy HH:mm:ss z", // Mon, 7 Jun 1976 13:02:09 EST
        "EEE, dd MMM yyyy HH:mm:ss z", // Mon, 07 Jun 1976 13:02:09 EST

        "EEE MMM dd HH:mm:ss z yyyy", // Mon Jun 07 13:02:09 EST 1976
        "EEE MMM d HH:mm:ss z yyyy", // Mon Jun 7 13:02:09 EST 1976

        "EEE MMM dd HH:mm:ss yyyy", // Mon Jun 07 13:02:09 1976
        "EEE MMM d HH:mm:ss yyyy", // Mon Jun 7 13:02:09 1976

        "yyyy-MM-dd HH:mm:ss.SSSZ", // 1976-06-07 01:02:09.000-0500
        "yyyy-MM-dd HH:mm:ss.SSS", // 1976-06-07 01:02:09.000

        "yyyy-MM-dd HH:mm:ssZ", // 1976-06-07 13:02:36-0500
        "yyyy-MM-dd HH:mm:ss", // 1976-06-07 01:02:09

        "yyyy:MM:dd HH:mm:ss", // 1976:06:07 01:02:09 (exif metadata)

        "yyyy-MM-dd-HH:mm:ss.SSS", // 1976-06-07-01:02:09.000
        "yyyy-MM-dd-HH:mm:ss", // 1976-06-07-01:02:09

        //"yyyy-MM-ddTHH:mm:ss.SSS",     // 1976-06-07T01:02:09.000
        //"yyyy-MM-ddTHH:mm:ss",         // 1976-06-07T01:02:09

        "dd-MMM-yyyy h:mm:ss a", // 07-Jun-1976 1:02:09 PM
        "dd-MMM-yy h:mm:ss a", // 07-Jun-76 1:02:09 PM
        //"d-MMM-yy h:mm:ss a",          // 7-Jun-76 1:02:09 PM

        "yyyy-MM-dd HH:mmZ", // 1976-06-07T13:02-0500
        "yyyy-MM-dd HH:mm", // 1976-06-07T13:02
        "yyyy-MM-dd", // 1976-06-07

        "dd-MMM-yy", // 07-Jun-76
        //"d-MMM-yy",                    // 7-Jun-76
        "dd-MMM-yyyy", // 07-Jun-1976
        "dd-MM-yyyy", // 07-06-1976
        "dd-MM-yyyy HH:mm", // 07-06-1976 13:02
        "dd-MM-yyyy HH:mm:ss", // 07-06-1976 13:02
        "dd-MM-yyyy HH:mm:ss.SSS", // 07-06-1976 13:02

        "MMMMMM d, yyyy", // June 7, 1976

        "M/d/yy h:mm:ss a", // 6/7/1976 1:02:09 PM
        "M/d/yy h:mm a", // 6/7/1976 1:02 PM

        //         "dd/MM/yyyy",                 // 07/06/1976
        //         "dd/MM/yyyy HH:mm",            // 07/06/1976 13:02
        "dd/MM/yyyy HH:mm:ss", // 07/06/1976 13:02:55
        "dd/MM/yyyy HH:mm:ss.SSS", // 07/06/1976 13:02:55.123
        "dd/MM/yyyy",
        
        "M/d/yy", // 6/7/76
        "M/d/yyyy", // 6/7/1976

        "yyyyMMddHHmmssSSS", // 19760607130200000
        "yyyyMMddHHmmss", // 19760607130200
        "yyyyMMdd" // 19760607
    };

    //**************************************************************************
    //** Constructor
    //**************************************************************************
    /**
     * Creates a new instance of date using current time stamp
     */
    public DateUtils() {
        currDate = new java.util.Date();
    }

    //**************************************************************************
    //** Constructor
    //**************************************************************************
    /**
     * Creates a new instance of date using supplied java.util.Date
     */
    public DateUtils(java.util.Date date) {
        currDate = date;
    }

    //**************************************************************************
    //** Constructor
    //**************************************************************************
    /**
     * Creates a new instance of date using supplied java.util.Calendar
     */
    public DateUtils(Calendar calendar) {
        currDate = calendar.getTime();
    }

    //**************************************************************************
    //** Constructor
    //**************************************************************************
    /**
     * Creates a new instance of date using a timestamp (in milliseconds) since
     * 1/1/1970
     */
    public DateUtils(long milliseconds) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(milliseconds);
        currDate = cal.getTime();
    }

    //**************************************************************************
    //** Constructor
    //**************************************************************************
    /**
     * Creates a new instance of date using a String representation of a date.
     */
    public DateUtils(String date) throws ParseException {

        try {

            //Special Case: Java fails to parse the "T" in strings like
            //"1976-06-07T01:02:09.000" and "1976-06-07T13:02-0500"
            if (date.length() >= "1976-06-07T13:02".length()) {
                if (date.substring(10, 11).equalsIgnoreCase("T")) {
                    date = date.replace("T", " ");
                }
            }

            //Loop through all known date formats and try to convert the string to a date
            for (int i = 0; i < SupportedFormats.length; i++) {

                //Special Case: Java fails to parse the "Z" in "1976-06-07 00:00:00Z"
                if (date.endsWith("Z") && SupportedFormats[i].endsWith("Z")) {
                    date = date.substring(0, date.length() - 1) + "UTC";
                }

                try {
                    currDate = parseDate(date, SupportedFormats[i]);
                    return;
                } catch (ParseException e) {
                }
            }

        } catch (Exception e) {
        }

        //If we're still here, throw an exception
        throw new ParseException("Failed to parse date: " + date, 0);

    }

    //**************************************************************************
    //** Constructor
    //**************************************************************************
    /**
     * Creates a new instance of date using a date string. The format string is
     * used to create a SimpleDateFormat to parse the input date string.
     */
    public DateUtils(String date, String format) throws ParseException {
        currDate = parseDate(date, format);
    }

    //**************************************************************************
    //** setDate
    //**************************************************************************
    /**
     * Used to update the current date using a date string. The format parameter
     * is used to create a SimpleDateFormat to parse the input date string.
     */
    public void setDate(String date, String format) throws ParseException {
        currDate = parseDate(date, format);
    }

    //**************************************************************************
    //** setDate
    //**************************************************************************
    /**
     * Used to update the current date using a predefined java.util.Date
     */
    public void setDate(java.util.Date date) {
        currDate = date;
    }

    //**************************************************************************
    //** ParseDate
    //**************************************************************************
    /**
     * Attempts to convert a String to a Date via the user-supplied Format
     */
    private java.util.Date parseDate(String date, String format) throws ParseException {

        if (date != null) {
            date = date.trim();
            if (date.length() == 0) {
                date = null;
            }
        }
        if (date == null) {
            throw new ParseException("Date is null.", 0);
        }

        SimpleDateFormat formatter = new SimpleDateFormat(format);
        if (this.timeZone != null) {
            formatter.setTimeZone(timeZone);
        }
        java.util.Date d = formatter.parse(date);
        this.timeZone = formatter.getTimeZone();
        return d;
    }

    //**************************************************************************
    //** setTimeZone
    //**************************************************************************
    /**
     * Used to set the current time zone. The time zone is used when comparing
     * and formatting dates.
     *
     * @param timeZone Name of the time zone (e.g. "UTC", "EDT", etc.)
     * @param preserveTimeStamp Flag used to indicate whether to preserve the
     * timestamp when changing time zones. Normally, when updating the timezone,
     * the timestamp is updated to the new timezone. For example, if the current
     * time is 4PM EST and you wish to switch to UTC, the timestamp would be
     * updated to 8PM. The preserveTimeStamp flag allows users to preserve the
     * the timestamp so that the timestamp remains fixed at 4PM.
     */
    public void setTimeZone(String timeZone, boolean preserveTimeStamp) {
        if (timeZone == null) {
            return;
        }
        java.util.TimeZone timezone = java.util.TimeZone.getTimeZone(timeZone);

        if (preserveTimeStamp) {

            String z1 = FormatDate(currDate, "z");

            SimpleDateFormat dateFormat = new SimpleDateFormat("z");
            dateFormat.setTimeZone(timezone);
            String z2 = dateFormat.format(currDate);

            String d = FormatDate(currDate, "yyyy-MM-dd HH:mm:ss.SSS z").replace(z1, z2);
            try {
                currDate = parseDate(d, "yyyy-MM-dd HH:mm:ss.SSS z");
            } catch (ParseException e) {
            }
        } else {
            this.timeZone = timezone;
        }
    }

    //**************************************************************************
    //** setTimeZone
    //**************************************************************************
    /**
     * Used to set the current time zone. The time zone is used when comparing
     * and formatting dates.
     *
     * @param timeZone Name of the time zone (e.g. "UTC", "EST", etc.)
     */
    public void setTimeZone(String timeZone) {
        setTimeZone(timeZone, false);
    }

    public void setTimeZone(java.util.TimeZone timeZone) {
        if (timeZone == null) {
            return;
        }
        this.timeZone = timeZone;
    }

    public java.util.TimeZone getTimeZone() {
        return this.timeZone;
    }

    //**************************************************************************
    //** toString
    //**************************************************************************
    /**
     * Returns the current date as a String in the following format: "EEE MMM dd
     * HH:mm:ss z yyyy"
     */
    @Override
    public String toString() {
        return toString("EEE MMM dd HH:mm:ss z yyyy");
    }

    //**************************************************************************
    //** toString
    //**************************************************************************
    /**
     * Used to format the current date into a string.
     *
     * @param format Pattern used to format the date (e.g. "EEE MMM dd HH:mm:ss
     * z yyyy"). Please refer to the SimpleDateFormat class for more
     * information.
     */
    public String toString(String format) {
        SimpleDateFormat currFormatter = new SimpleDateFormat(format);
        if (timeZone != null) {
            currFormatter.setTimeZone(timeZone);
        }
        return currFormatter.format(currDate);
    }

    //**************************************************************************
    //** toLong
    //**************************************************************************
    /**
     * Returns a long integer used to represent the Date in the following
     * format: "yyyyMMddHHmmssSSS". Please use the getTime() method to get the
     * the number of milliseconds since January 1, 1970, 00:00:00 UTC.
     */
    public long toLong() {
        return Long.parseLong(this.toString("yyyyMMddHHmmssSSS"));
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 59 * hash + Objects.hashCode(this.currDate);
        return hash;
    }

    //**************************************************************************
    //** equals
    //**************************************************************************
    /**
     * Used to compare dates and determine whether they are equal.
     *
     * @param obj Accepts a java.util.Date, a com.hmt.framework.util.Date, or a
     * String.
     */
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof DateUtils) {
            return ((DateUtils) obj).getDate().equals(currDate);
        } else if (obj instanceof java.util.Date) {
            return ((java.util.Date) obj).equals(currDate);
        } else if (obj instanceof String) {
            try {
                return (new DateUtils((String) obj)).getDate().equals(currDate);
            } catch (ParseException e) {
            }
        }
        return false;
    }

    //**************************************************************************
    //** FormatDate
    //**************************************************************************
    private String FormatDate(java.util.Date date, String OutputFormat) {
        SimpleDateFormat formatter = new SimpleDateFormat(OutputFormat);
        if (timeZone != null) {
            formatter.setTimeZone(timeZone);
        }
        return formatter.format(date);
    }

    //**************************************************************************
    //** compareTo
    //**************************************************************************
    /**
     * Used to compare dates. Returns the number of intervals between two dates
     *
     * @param units Units of measure (e.g. hours, minutes, seconds, weeks,
     * months, years, etc.)
     */
    public long compareTo(DateUtils date, String units) {
        return DateDiff(currDate, date.getDate(), units);
    }

    //**************************************************************************
    //** compareTo
    //**************************************************************************
    /**
     * Used to compare dates. Returns the number of intervals between two dates
     *
     * @param units Units of measure (e.g. hours, minutes, seconds, weeks,
     * months, years, etc.)
     */
    public long compareTo(java.util.Date date, String units) {
        return DateDiff(currDate, date, units);
    }

    //**************************************************************************
    //** DateDiff
    //**************************************************************************
    /**
     * Implements compareTo public members
     */
    private long DateDiff(java.util.Date date1, java.util.Date date2, String interval) {

        double div = 1;
        if (interval.equals("S") || interval.toLowerCase().startsWith("sec")) {
            div = 1000L;
        }
        if (interval.equals("m") || interval.toLowerCase().startsWith("min")) {
            div = 60L * 1000L;
        }
        if (interval.equals("H") || interval.toLowerCase().startsWith("h")) {
            div = 60L * 60L * 1000L;
        }
        if (interval.equals("d") || interval.toLowerCase().startsWith("d")) {
            div = 24L * 60L * 60L * 1000L;
        }
        if (interval.equals("w") || interval.toLowerCase().startsWith("w")) {
            div = 7L * 24L * 60L * 60L * 1000L;
        }
        if (interval.equals("M") || interval.toLowerCase().startsWith("mon")) {
            div = 30L * 24L * 60L * 60L * 1000L;
        }
        if (interval.equals("y") || interval.toLowerCase().startsWith("y")) {
            div = 365L * 24L * 60L * 60L * 1000L;
        }

        long d1 = date1.getTime();
        long d2 = date2.getTime();

        int i2 = (int) Math.abs((d1 - d2) / div);
        if (date2.after(date1)) {
            i2 = -i2;
        }

        return i2;
    }

    public boolean isBefore(DateUtils Date) {
        return currDate.before(Date.getDate());
    }

    public boolean isAfter(DateUtils Date) {
        return currDate.after(Date.getDate());
    }

    //**************************************************************************
    //** Add
    //**************************************************************************
    /**
     * Used to add to (or subtract from) the current date. Returns a date to
     * which a specified time interval has been added.
     *
     * @param units Unit of measure (e.g. hours, minutes, seconds, days, weeks,
     * months, years, etc.)
     */
    public java.util.Date add(int amount, String units) {

        Calendar cal = Calendar.getInstance();
        cal.setTime(currDate);

        int div = 0;
        if (units.equals("S") || units.toLowerCase().startsWith("millisecond")) {
            div = Calendar.MILLISECOND;
        } else if (units.equals("s") || units.toLowerCase().startsWith("sec")) {
            div = Calendar.SECOND;
        } else if (units.equals("m") || units.toLowerCase().startsWith("min")) {
            div = Calendar.MINUTE;
        } else if (units.equals("H") || units.toLowerCase().startsWith("h")) {
            div = Calendar.HOUR_OF_DAY;
        } else if (units.equals("d") || units.toLowerCase().startsWith("d")) {
            div = Calendar.DAY_OF_YEAR;
        } else if (units.equals("w") || units.toLowerCase().startsWith("w")) {
            div = Calendar.WEEK_OF_YEAR;
        } else if (units.equals("M") || units.toLowerCase().startsWith("mon")) {
            div = Calendar.MONTH;
        } else if (units.equals("y") || units.toLowerCase().startsWith("y")) {
            div = Calendar.YEAR;
        }
        cal.add(div, amount);
        currDate = cal.getTime();
        return currDate;
    }

    //**************************************************************************
    //** getDate
    //**************************************************************************
    /**
     * Returns the java.utils.Date representation of this object
     */
    public java.util.Date getDate() {
        return currDate;
    }

    //**************************************************************************
    //** getTime
    //**************************************************************************
    /**
     * Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
     * represented by this Date object.
     */
    public long getTime() {
        return getCalendar().getTimeInMillis();
    }

    //**************************************************************************
    //** getCalendar
    //**************************************************************************
    /**
     * Returns the java.utils.Calender representation of this object
     */
    public Calendar getCalendar() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(currDate);
        if (this.timeZone != null) {
            cal.setTimeZone(timeZone);
        }
        return cal;
    }

    //**************************************************************************
    //** getWeekdayName
    //**************************************************************************
    /**
     * Returns the name of the day of the week. Example: "Monday"
     */
    public String getWeekdayName() {
        return FormatDate(currDate, "EEEEEE");
    }

    //**************************************************************************
    //** getHourMinute
    //**************************************************************************
    /**
     * Returns the hour and munite. Example: "15:45"
     */
    public String getHourMinute() {
        return FormatDate(currDate, "HH:mm");
    }

    //**************************************************************************
    //** getHourMinute
    //**************************************************************************
    /**
     * Returns the date. Example: "22/02/1983"
     */
    public String getFullDate() {
        return FormatDate(currDate, "dd/MM/yyyy");
    }

    //**************************************************************************
    //** getWeekdayName
    //**************************************************************************
    /**
     * Returns the name of the month. Example: "January"
     */
    public String getMonthName() {
        return FormatDate(currDate, "MMMMMM");
    }

    //**************************************************************************
    //** getDayOfWeek
    //**************************************************************************
    /**
     * Returns the day of the week. Example: Monday = 1
     */
    public int getDayOfWeek() {
        return Integer.valueOf(FormatDate(currDate, "F")).intValue();
    }

    //**************************************************************************
    //** getWeekInMonth
    //**************************************************************************
    /**
     * Returns the week number in a given month. Example: 11/14/2006 = 3
     */
    public int getWeekInMonth() {
        return Integer.valueOf(FormatDate(currDate, "W")).intValue();
    }

    //**************************************************************************
    //** getDayInYear
    //**************************************************************************
    /**
     * Returns the day of the year. Example: 11/14/2006 = 318
     */
    public int getDayInYear() {
        return Integer.valueOf(FormatDate(currDate, "D")).intValue();
    }

    //**************************************************************************
    //** getWeekInYear
    //**************************************************************************
    /**
     * Returns the week number within a given year. Example: 11/14/2006 = 46
     */
    public int getWeekInYear() {
        return Integer.valueOf(FormatDate(currDate, "w")).intValue();
    }

    //**************************************************************************
    //** getYear
    //**************************************************************************
    /**
     * Returns the current year. Example: 11/14/2006 = 2006
     */
    public int getYear() {
        return Integer.valueOf(FormatDate(currDate, "yyyy")).intValue();
    }

    //**************************************************************************
    //** getMonth
    //**************************************************************************
    /**
     * Returns the current month. Example: 11/14/2006 = 11
     */
    public int getMonth() {
        return Integer.valueOf(FormatDate(currDate, "MM")).intValue();
    }

    //**************************************************************************
    //** getDay
    //**************************************************************************
    /**
     * Returns the current day of the month. Example: 11/14/2006 = 14
     */
    public int getDay() {
        return Integer.valueOf(FormatDate(currDate, "dd")).intValue();
    }

    //**************************************************************************
    //** getHour
    //**************************************************************************
    /**
     * Returns the current hour of the day. Example: 12:00 AM = 0, 1:00 PM = 13
     */
    public int getHour() {
        return Integer.valueOf(FormatDate(currDate, "HH")).intValue();
    }

    //**************************************************************************
    //** getMinute
    //**************************************************************************
    /**
     * Returns the current minute of the hour. Example: 12:01 = 1
     */
    public int getMinute() {
        return Integer.valueOf(FormatDate(currDate, "m")).intValue();
    }

    //**************************************************************************
    //** getSecond
    //**************************************************************************
    /**
     * Returns the current second of the minute. Example: 12:00:01 = 1
     */
    public int getSecond() {
        return Integer.valueOf(FormatDate(currDate, "s")).intValue();
    }

    //**************************************************************************
    //** getMilliSecond
    //**************************************************************************
    /**
     * Returns the current millisecond of the second. Example: 12:00:00:01 = 1
     */
    public int getMilliSecond() {
        return Integer.valueOf(FormatDate(currDate, "S")).intValue();
    }

    //**************************************************************************
    //** hasTimeStamp
    //**************************************************************************
    /**
     * Used to determine whether a date has a timestamp.
     */
    public boolean hasTimeStamp() {
        return hasTimeStamp(getDate());
    }

    private static boolean hasTimeStamp(java.util.Date date) {
        java.util.Calendar cal = java.util.Calendar.getInstance();
        cal.setTime(date);
        int hour = cal.get(java.util.Calendar.HOUR);
        int min = cal.get(java.util.Calendar.MINUTE);
        int sec = cal.get(java.util.Calendar.SECOND);
        int ms = cal.get(java.util.Calendar.MILLISECOND);
        if (hour > 0 || min > 0 || sec > 0 || ms > 0) {
            return true;
        }
        return false;
    }

    /**
     *
     * @param sessionTime
     * @return the timestamp from sessionTime to now. Example: 4 hours ago
     */
    public String timestamp(long sessionTime, boolean isVietNamese) {

        long time_difference = System.currentTimeMillis() - sessionTime;
        long seconds = time_difference / 1000;
        long minutes = time_difference / 60000;
        long hours = time_difference / 3600000;
        long days = time_difference / 86400000;
//		long weeks = time_difference / 604800000;
//		long months = time_difference / 2419200000l;
//		long years = time_difference / 29030400000l;
        DateUtils date = new DateUtils(sessionTime);
        DateUtils curr = new DateUtils(System.currentTimeMillis());
        if (seconds <= 60) {
            return seconds + (isVietNamese ? " giây trước" : " seconds ago");
        } else if (minutes <= 60) {
            return minutes + (isVietNamese ? " phút trước" : " minutes ago");
        } else if (hours <= 23) {
            return hours + (isVietNamese ? " giờ " : " hours ") + (minutes - hours * 60) + (isVietNamese ? " phút trước" : " minutes ago");
        } else if (days <= 7) {
            if (days == 1) {
                return date.getHourMinute() + " " + timeToSessions(date.getHour()) + (isVietNamese ? " hôm qua" : " yesterday");
            } else {
                return date.getHourMinute() + " " + timeToSessions(date.getHour()) + " " + date.getWeekdayName() + (curr.getWeekInYear() != date.getWeekInYear() ? (isVietNamese ? " tuần trước" : " last week") : "");
            }
        } else {
            return date.getHourMinute() + " " + timeToSessions(date.getHour()) + " " + date.getFullDate();
//		}else if (weeks <= 4) {
//			return weeks + " tuần trước";
//		} else if (months <= 12) {
//			return months + " tháng trước";
//		}
//		else {
//			return years + " năm trước";
        }
    }

    public String timeToSessions(int time) {
        if (time <= 10) {
            return "sáng";
        } else if (time <= 14) {
            return "trưa";
        } else if (time <= 18) {
            return "chiều";
        } else {
            return "tối";
        }
    }

    private static class DateComparer implements java.util.Comparator<Object> {

        @Override
        public final int compare(Object a, Object b) {

            if (a == null || b == null) {
                return -1;
            }

            java.util.Date d1 = null;
            java.util.Date d2 = null;

            if (a instanceof java.util.Date) {
                d1 = ((java.util.Date) a);
            } else if (a instanceof DateUtils) {
                d1 = ((DateUtils) a).getDate();
            }

            if (b instanceof java.util.Date) {
                d2 = ((java.util.Date) b);
            } else if (b instanceof DateUtils) {
                d2 = ((DateUtils) b).getDate();
            }

            if (d1 == null || d2 == null) {
                return -1;
            }

            Long x = d1.getTime();
            Long y = d2.getTime();
            int result = x.compareTo(y);

            //The following block of code is used to tweak the results when
            //comparing 2 dates that have the same day, month, and year but one
            //of the dates doesn't have a timestamp. The date with the timestamp
            //will come out older that the date without the timestamp.

            if (result != 0) {

                java.util.Calendar c1 = java.util.Calendar.getInstance();
                c1.setTime(d1);

                java.util.Calendar c2 = java.util.Calendar.getInstance();
                c2.setTime(d2);

                if (c1.get(java.util.Calendar.YEAR) == c2.get(java.util.Calendar.YEAR)) {
                    if (c1.get(java.util.Calendar.MONTH) == c2.get(java.util.Calendar.MONTH)) {
                        if (c1.get(java.util.Calendar.DATE) == c2.get(java.util.Calendar.DATE)) {
                            if (hasTimeStamp(d1) == true && hasTimeStamp(d2) == false) {
                                result = -1;
                            } else if (hasTimeStamp(d1) == false && hasTimeStamp(d2) == true) {
                                result = 1;
                            }
                        }
                    }
                }

            }

            return result;
        }
    }

    //**************************************************************************
    //** sortDates
    //**************************************************************************
    /**
     * Static method used to sort dates in a list. Older dates appear first in
     * the output.
     */
    @SuppressWarnings("unchecked")
    public static java.util.List sortDates(java.util.List dates) {
        while (dates.contains(null)) {
            dates.remove(null);
        }
        java.util.Collections.sort(dates, new DateComparer());
        return dates;
    }

    public static void main(String[] args) {
        DateUtils a = new DateUtils();
        System.out.println(a.getMonthName());

    }
}
